import { defineStore } from "pinia";

export const userInfoStore = defineStore('user', {
    state: () => ({
        id: '',
        username: '',
        phoneNumber: '',
        headPortraitUrl: '',
        password: ''
    }),
    getters: {

    },
    actions: {
        update(id?: string, username?: string, phoneNumber?: string, headPortraitUrl?: string, password?: string) {
            this.headPortraitUrl = headPortraitUrl ? headPortraitUrl : this.headPortraitUrl;
            this.id = id ? id : this.id;
            this.username = username ? username : this.username;
            this.phoneNumber = phoneNumber ? phoneNumber : this.phoneNumber;
            this.password = password ? password : this.password;
        },
        reset() {
            this.headPortraitUrl = '';
            this.id = '';
            this.username = '';
            this.phoneNumber = '';
            this.password = '';
        },
        setUrl(headPortraitUrl?: string) {
            this.headPortraitUrl = headPortraitUrl ? headPortraitUrl : this.headPortraitUrl;
        }
    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'user',
                storage: localStorage,
                paths: ['id', 'username', 'headPortraitUrl', 'phoneNumber', 'password']
            }
        ]
    }
});
